package com.feiyuan.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.feiyuan.annotation.FeiyuanRequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.feiyuan.modules.sys.entity.DictEntity;
import com.feiyuan.modules.sys.service.DictService;
import com.feiyuan.common.utils.PageUtils;
import com.feiyuan.common.utils.ResponseUtils;

/**
 * 字典管理控制器
 * @author Xupf
 * @email xupengfei131276@126.com
 * @date 2024-06-24 16:50:51
 */
@RestController
@RequestMapping("/admin/sys/dict")
public class DictController {
    @Autowired
    private DictService dictService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @FeiyuanRequiresPermissions("sys:dict:list")
    public ResponseUtils list(@RequestParam Map<String, Object> params){
        PageUtils page = dictService.queryPage(params);

        return ResponseUtils.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @FeiyuanRequiresPermissions("sys:dict:info")
    public ResponseUtils info(@PathVariable("id") Long id){
		DictEntity dict = dictService.getById(id);

        return ResponseUtils.ok().put("dict", dict);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @FeiyuanRequiresPermissions("sys:dict:save")
    public ResponseUtils save(@RequestBody DictEntity dict){
		dictService.save(dict);

        return ResponseUtils.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @FeiyuanRequiresPermissions("sys:dict:update")
    public ResponseUtils update(@RequestBody DictEntity dict){
        dict.setUpdateTime(new Date());
		dictService.updateById(dict);

        return ResponseUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @FeiyuanRequiresPermissions("sys:dict:delete")
    public ResponseUtils delete(@RequestBody Long[] ids){
		dictService.removeByIds(Arrays.asList(ids));

        return ResponseUtils.ok();
    }

}
